package cn.kingyea.utils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.Logger;

/**
 * Hbase配置信息工具类 
 * @author 何海亮
 *
 */
public class HbaseConUtil {
	private static final Logger LOGGER = Logger.getLogger(HbaseConUtil.class);
	static Configuration conf=null;
	static {
		conf = new Configuration();
	    String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
	    conf.addResource(new Path(userdir + "core-site.xml"));
	    conf.addResource(new Path(userdir + "hdfs-site.xml"));
	    conf.addResource(new Path(userdir + "hbase-site.xml"));
	}
	public static Configuration getConfiguration(){
		return conf;
	}
	
	/*public  void login() throws IOException {
		LOGGER.info(confs);
		if (User.isHBaseSecurityEnabled(confs)) {
		      String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
		      userName = "hbaseuser1";
		      userKeytabFile = userdir + "user.keytab";
		      krb5File = userdir + "krb5.conf";
		      
		       * if need to connect zk, please provide jaas info about zk. of course,
		       * you can do it as below:
		       * System.setProperty("java.security.auth.login.config", confDirPath +
		       * "jaas.conf"); but the demo can help you more : Note: if this process
		       * will connect more than one zk cluster, the demo may be not proper. you
		       * can contact us for more help
		       
		      LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_LOGIN_CONTEXT_NAME, userName, userKeytabFile);
		      LoginUtil.setZookeeperServerPrincipal(ZOOKEEPER_SERVER_PRINCIPAL_KEY,
		          ZOOKEEPER_DEFAULT_SERVER_PRINCIPAL);
		      LoginUtil.login(userName, userKeytabFile, krb5File, conf);
		}else{
			LOGGER.info("不进行登录");
		}
	}*/
	
//		public static void main(String[] args) throws IOException {
//			Configuration confs = new Configuration();
//		    String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
//		    confs.addResource(new Path(userdir + "core-site.xml"));
//		    confs.addResource(new Path(userdir + "hdfs-site.xml"));
//		    confs.addResource(new Path(userdir + "hbase-site.xml"));
//		    LOGGER.info(confs);
//			HbaseTableLoader.logins(confs);
//			Connection hbaseConn = ConnectionFactory.createConnection(confs);
//			//testScanData(hbaseConn);
//			LOGGER.info("-----------finish HBase -------------------");
//	}
}
